package com.mcp.mcpserver.config;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
/**
 * @author zhangxin569
 * @date 2025/8/6
 * 自定义的动态数据源类，用于在运行时根据键切换不同的数据源。
 *
 */
public class DynamicDataSource extends AbstractRoutingDataSource {
    private static final ThreadLocal<String> dataSourceKey = new InheritableThreadLocal<>();
    public static void setDataSourceKey(String key) {
        dataSourceKey.set(key);
    }

    public static void clearDataSourceKey() {
        dataSourceKey.remove();
    }

    @Override
    protected Object determineCurrentLookupKey() {
        return dataSourceKey.get();
    }
}